#pragma once

#include "Util.hpp"
#include <iostream>
#include <string>
#include <sstream>

const std::string sep = "\r\n";
const std::string default_root = "./wwwroot";   //web根目录
const std::string home_page = "index.html";     //默认首页
const std::string html_404="wwwroot/404.html";

class httpRequest
{
public:
    httpRequest()
    {
    }

    void parse()
    {
        // 1.从inbuf中获取请求行
        std::string line = Util::getOneLine(inbuf, sep);
        // 2，从请求行提取三个字段
        std::stringstream ss(line);
        ss >> method >> url >> httpVersion;

        // 3.添加web默认路径
        path = default_root;              // 默认路径不以/结尾，因为url中的文件路径以/起手
        path += url;                      //./wwwroot/a/b/c.html
        if (path[path.size() - 1] == '/') // url中路径为/时
            path += home_page;
    }

public:
    std::string inbuf;
    std::string method;
    std::string url;
    std::string httpVersion;
    std::string path;
};

class httpResponse
{
public:
    httpResponse()
    {
    }

public:
    std::string outbuf;
    std::string respLine;
    std::string respHeader;
    std::string respBlank;
    std::string body;
};




